import java.util.concurrent.TimeUnit;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

public class Format {

	public static long getPartition(long timeGranularityMs, long timestamp, DateTimeZone timeZone) {
		long adjustedTimeStamp = timeZone.convertUTCToLocal(timestamp);
		long partitionedTime = (adjustedTimeStamp / timeGranularityMs) * timeGranularityMs;
		System.out.println(adjustedTimeStamp);
		System.out.println(partitionedTime);
		return timeZone.convertLocalToUTC(partitionedTime, false);
	}

	public static String encodePartition(String formatter) {
		long timestamp = System.currentTimeMillis();
		DateTime bucket = new DateTime(timestamp);
		return bucket.toString(formatter);
	}

	public static void main(String[] args) throws Exception {
		System.out.println(encodePartition("'year'=YYYY/'month'=MM/'day'=dd/"));

		System.out.println(encodePartition("YYYYMM/YYYYMMdd/YYYYMMddHH/"));

		for (int i = 0; i < 5; i++) {
			getPartition(TimeUnit.HOURS.toMillis(1), System.currentTimeMillis(), DateTimeZone.forID("Asia/Shanghai"));
			Thread.sleep(2000);
		}
	}

}
